//
//  UIImage+PGExtend.m
//  youqu
//
//  Created by 彭鹏 on 16/9/3.
//  Copyright © 2016年 pengpeng. All rights reserved.
//

#import "UIImage+PGExtend.h"

@implementation UIImage (PGExtend)
//获得不被拉伸的图片
+ (UIImage *)stretchableImageWithName:(NSString *)imageNamed {
    UIImage *image = [UIImage imageNamed:imageNamed];
    return [image stretchableImageWithLeftCapWidth:image.size.width*0.5 topCapHeight:image.size.height*0.5];
}
//获得原始不被拉伸的图片
+ (UIImage *)imageOriginal:(NSString *)imageNamed {
    UIImage *image = [UIImage imageNamed:imageNamed];
    return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

//获得圆形图片
- (UIImage *)imageCicle:(UIImage *)image {
    //1.获得图形上下文
    UIGraphicsBeginImageContext(image.size);
    
    //2.设置圆形区域
    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
    
    //3.设置裁剪区域
    [bezierPath addClip];
    
    //4.讲图片画到裁剪区域上
    [image drawAtPoint:CGPointZero];
    
    //5.从当前上下文中获取图片
    image = UIGraphicsGetImageFromCurrentImageContext();
    
    //6.关闭图形上下文
    UIGraphicsEndImageContext();
    
    return image;
}

//获得圆形图片
+ (UIImage *)imageCicle:(NSString *)imageName; {
    UIImage *image = [UIImage imageNamed:imageName];
    return [image imageCicle:image];
}


@end
